import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '主页',
      // component: () => import('@/views/dashboard/index'),
      component: resolve => require(['../views/dashboard/dashboard.vue'], resolve),
      meta: { title: '主页', icon: 'dashboard' }
    }]
  },
  // {
  //   path: '/todoList',
  //   component: Layout,
  //   redirect: '/todoList',
  //   name: '待办业务',
  //   meta: { title: '待办业务', icon: 'example' },
  //   children: [
  //     {
  //       path: '',
  //       name: '待办业务',
  //       component: resolve => require(['../views/todoList/todoList.vue'], resolve),
  //       meta: { title: '待办业务', icon: 'example' }
  //     }
  //   ]
  // },
  {
    path: '/assetBusiness',
    component: Layout,
    redirect: '/assetBusiness/registration',
    name: '资产业务',
    meta: { title: '资产业务', icon: 'example' },
    children: [
      {
        path: 'registration',
        name: '登记入库',
        // component: () => import('@/views/assetBusiness/registration'),
        component: resolve => require(['../views/assetBusiness/registration/registration.vue'], resolve),
        meta: { title: '登记入库', icon: 'table' }
      },
      {
        path: 'review',
        name: '资产审核',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/assetBusiness/review/review.vue'], resolve),
        meta: { title: '资产审核', icon: 'tree' }
      },
      {
        path: 'useAsset',
        name: '资产领用',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/assetBusiness/useAsset/useAsset.vue'], resolve),
        meta: { title: '资产领用', icon: 'table' }
      },
      {
        path: 'returnAsset',
        name: '资产归还',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/assetBusiness/returnAsset/returnAsset.vue'], resolve),
        meta: { title: '资产归还', icon: 'tree' }
      },
      {
        path: 'maintenance',
        name: '资产维修',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/assetBusiness/maintenance/maintenance.vue'], resolve),
        meta: { title: '资产维修', icon: 'table' }
      },
      {
        path: 'disposal',
        name: '资产处置',
        // component: () => import('@/views/assetBusiness/review'),
        component: resolve => require(['../views/assetBusiness/disposal/disposal.vue'], resolve),
        meta: { title: '资产处置', icon: 'tree' }
      }
    ]
  },
  {
    path: '/queryDisplay',
    component: Layout,
    redirect: '/queryDisplay/accountInquiry',
    name: '查询展示',
    meta: { title: '查询展示', icon: 'example' },
    children: [
      {
        path: 'accountInquiry',
        name: '台账查询',
        component: resolve => require(['../views/queryDisplay/accountInquiry/accountInquiry.vue'], resolve),
        meta: { title: '台账查询', icon: 'table' }
      },
      {
        path: 'inventory',
        name: '资产盘点',
        component: resolve => require(['../views/queryDisplay/inventory/inventory.vue'], resolve),
        meta: { title: '资产盘点', icon: 'table' }
      },
      {
        path: 'depreciation',
        name: '资产折旧',
        component: resolve => require(['../views/queryDisplay/depreciation/depreciation.vue'], resolve),
        meta: { title: '资产折旧', icon: 'table' }
      },
      {
        path: 'check',
        name: '盘点',
        component: resolve => require(['../views/queryDisplay/check/check.vue'], resolve),
        meta: { title: '盘点', icon: 'table' },
        hidden: true
      },
      // {
      //   path: 'chartDisplay',
      //   name: '图表展示',
      //   component: resolve => require(['../views/queryDisplay/chartDisplay/chartDisplay.vue'], resolve),
      //   meta: { title: '图表展示', icon: 'table' }
      // }
    ]
  },
  {
    path: '/gps',
    component: Layout,
    redirect: '/gps/floor',
    name: '定位功能',
    meta: { title: '定位功能', icon: 'example' },
    children: [
      {
        path: 'floor',
        name: '楼层定位',
        component: resolve => require(['../views/gps/floor/floor.vue'], resolve),
        meta: { title: '楼层定位', icon: 'table' }
      },
      {
        path: 'idBind',
        name: '标签绑定',
        component: resolve => require(['../views/gps/idBind/idBind.vue'], resolve),
        meta: { title: '标签绑定', icon: 'table' },
        hidden: true
      },
      {
        path: 'idManage',
        name: '位置管理',
        component: resolve => require(['../views/gps/idManage/idManage.vue'], resolve),
        meta: { title: '位置管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/management',
    component: Layout,
    redirect: '/management/company',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'example' },
    children: [
      {
        path: 'company',
        name: '公司管理',
        component: resolve => require(['../views/management/company/company.vue'], resolve),
        meta: { title: '公司管理', icon: 'table' }
      },
      {
        path: 'classes',
        name: '资产分类',
        component: resolve => require(['../views/queryDisplay/classes/AassetClasses'], resolve),
        meta: { title: '资产分类', icon: 'table' }
      },
      // {
      //   path: 'personalSettings',
      //   name: '个人设置',
      //   component: resolve => require(['../views/management/personalSettings/personalSettings.vue'], resolve),
      //   meta: { title: '个人设置', icon: 'table' }
      // },
      {
        path: 'dict',
        name: '数据字典',
        component: resolve => require(['../views/management/dict/SysDict.vue'], resolve),
        meta: { title: '数据字典', icon: 'table' }
      },
      {
        path: 'userPermissionSettings',
        name: '用户管理',
        component: resolve => require(['../views/management/userPermissionSettings/userPermissionSettings.vue'], resolve),
        meta: { title: '用户管理', icon: 'table' }
      }
    ]
  },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
